-- Decompiled with the Synapse X Luau decompiler.

local CommonOHOH = _G.CommonOHOH;

local M = CommonOHOH.class.new(script, CommonOHOH.files.CommonObject());
function M.ctor(self, p2, p3)
	assert(p2, "param inst is nil");
	M.super.ctor(self);
	self:SetMainInst(p2);
	-- self.__components = {};
end;
local ObjectManager = CommonOHOH.load.ObjectManager();
function M.dtor(p4)
	-- for v2, v3 in pairs(p4.__components) do
	-- 	coroutine.resume((coroutine.create(function()
	-- 		local v4, v5 = xpcall(v3.dtor, debug.traceback, v3);
	-- 		if not v4 then
	-- 			v3[v2] = nil;
	-- 			ObjectManager:DelObject(v3);
	-- 		end;
	-- 	end)));
	-- end;
	-- while next(p4.__components) and os.clock() - os.clock() <= 10 do
	-- 	wait();	
	-- end;
	p4:DelMainInst();
	M.super.dtor(p4)
end;
-- function M.AddComponent(p5, p6,...)
-- 	return p5.__components[p6.class] or p6.new(p5,...);
-- end;
-- function M.GetComponent(p7, p8)
-- 	return p7.__components[p8.class];
-- end;
local InstanceManager = CommonOHOH.load.InstanceManager();
function M.GetChildrenObjects(p9)
	assert(p9.main_inst, "object main inst is nil class name = " .. p9.class);
	local v6 = {};
	for v7, v8 in ipairs((p9.main_inst:GetChildren())) do
		table.insert(v6, (InstanceManager:FindObject(v8)));
	end;
	return v6;
end;
function M.GetParentObject(p10)
	assert(p10.main_inst, "object main inst is nil class name = " .. p10.class);
	local l__Parent__9 = p10.main_inst.Parent;
	if not l__Parent__9 then
		return;
	end;
	return InstanceManager:FindObject(l__Parent__9);
end;
function M.GetName(p11)
	assert(p11.main_inst, "object main inst is nil class name = " .. p11.class);
	return p11.main_inst.Name;
end;
function M.SetName(p12, p13)
	assert(p13, "param name is nil");
	assert(p12.main_inst, "object main inst is nil class name = " .. p12.class);
	p12.main_inst.Name = p13;
end;
function M.SetParentObject(p14, p15)
	assert(p15, "param object is nil");
	assert(p15.main_inst, "parent object main inst is nil class name = " .. p15.class);
	assert(p14.main_inst, "object main inst is nil class name = " .. p14.class);
	p14.main_inst.Parent = p15.main_inst;
end;
function M.SetParentInstance(p16, p17)
	assert(p17, "param object is nil");
	assert(p16.main_inst, "object main inst is nil class name = " .. p16.class);
	p16.main_inst.Parent = p17;
end;
local CallBackManager = CommonOHOH.load.CallBackManager();
function M.AddHandleOnParentChange(self, handle, isDisconnect, ...)
	assert(handle, "param handle is ni");
	assert(self.main_inst, "object main inst is nil class name = " .. self.class);
	local RbxConnect = nil;
	local arg = { ... };
	RbxConnect = CallBackManager:AddRbxConnect(self, self.main_inst.Changed, function(object, property)
		if property == "Parent" then
			if isDisconnect then
				RbxConnect:Disconnect();
			end;
			handle(object, object.main_inst.Parent, table.unpack(arg));
		end;
	end);
	return nil;
end;



--self:AddHandleOnInWorkspace(self.SetNetworkOwner, true, player);
function M.AddHandleOnInWorkspace(self, fuc, isDisconnect, ...)
	assert(fuc, "param handle is nil");
	assert(self.main_inst, "object main inst is nil class name = " .. self.class);
	local arg = { ... };
	return self:AddHandleOnParentChange(function(object, parent)
		if parent and parent:IsDescendantOf(workspace) then
			--fuc(self, parent, table.unpack(arg));--错误代码
			fuc(self, table.unpack(arg));

		end;
	end, isDisconnect, table.unpack(arg));
end;


function M.AddHandleOnChildRemoved(self, handle, isDisconnect, ...)
	
	assert(handle, "param handle is ni");
	assert(self.main_inst, "object main inst is nil class name = " .. self.class);
	local RbxConnect = nil;
	local arg = { ... };
	RbxConnect = CallBackManager:AddRbxConnect(self, self.main_inst.ChildRemoved, function(object, child)
		if isDisconnect then
			RbxConnect:Disconnect();
		end;
		self:AddProcess(function()
			self:Wait(0.2)
			handle(object,table.unpack(arg),child);
		end)
	end);
	
end;

function M.AddHandleOnChildAdd(self, handle, isDisconnect, ...)
	
	assert(handle, "param handle is ni");
	assert(self.main_inst, "object main inst is nil class name = " .. self.class);
	local RbxConnect = nil;
	local arg = { ... };
	RbxConnect = CallBackManager:AddRbxConnect(self, self.main_inst.ChildAdded, function(object, child)
		if isDisconnect then
			RbxConnect:Disconnect();
		end;
		self:AddProcess(function()
			self:Wait(0.2)
			handle(object,table.unpack(arg),child);
		end)
	end);

	
end;

local HideClassName=CommonOHOH.load.RBLX_Class_Type()

function M.HideGameObject(self, p55)
	
end

function M.SetAllTransparency(self, p55)

	self.transparencyAllData={}
	for v31, v32 in ipairs(self.main_inst:GetDescendants()) do
		
		if p55==1 then --隐藏
			
			local isHadEnabled=false
			local isParentHadEnabled=false

			for _,class in pairs(HideClassName.HideEnabled) do
				if v32:IsA(class) then --是该类
					isHadEnabled=true
					break
				elseif v32:FindFirstAncestorOfClass(class) then --父级是该类
					isParentHadEnabled=true
					break
				end
				
	
			end
			
			if isParentHadEnabled then
				continue
			elseif isHadEnabled  then
				if v32.Enabled then
					v32.Enabled=false
					self.transparencyAllData[v32]=true
				end
				continue
			end
			
			--if isHadEnabled  then
			--	if v32.Enabled then
			--		v32.Enabled=false
			--		self.transparencyAllData[v32]=true
			--	end
			--	continue
			--end
		end
		
		local transparency=nil
		local success, response = pcall(function()
			transparency = v32.Transparency
		end)
		if success and type(transparency)=="number" then
			self.transparencyAllData[v32]=transparency
			v32.Transparency = p55
		end

	end;
	
end;

function M.recoverAllTransparency(self, p55)

	if not self.transparencyAllData then
		return
	end
	
	for k,v in pairs(self.transparencyAllData) do
		local isHadEnabled=false
		for _,class in pairs(HideClassName.HideEnabled) do
			if k:IsA(class) then --是该类
				isHadEnabled=true
				break
			end
		end
		
		if isHadEnabled then
			k.Enabled=v
		else
			k.Transparency=v
		end
	end

	--for v31, v32 in ipairs(self.main_inst:GetDescendants()) do
	--	if  self.transparencyAllData[v32]  then
	--		v32.Transparency = self.transparencyAllData[v32];
	--	end;
	--end;

	self.transparencyAllData=nil
end;


return M;
